1 00:00:00,560 --> 00:00:01,340 Okay. 2 00:00:01,340 --> 00:00:06,050 The next thing we need to script is our task service, which will be responsible for setting up the 3 00:00:06,050 --> 00:00:08,060 tasks for the players to complete. 4 00:00:08,060 --> 00:00:11,180 We're going to have a total of four tasks. 5 00:00:11,180 --> 00:00:15,560 One is going to be where the player needs to clean any dirty tables. 6 00:00:15,560 --> 00:00:19,760 So we have crumbs here that we can take out of the server storage real quick. 7 00:00:19,760 --> 00:00:21,290 And we'll put this in the workspace. 8 00:00:21,290 --> 00:00:25,310 And these crumbs will be positioned randomly around on each of these tables. 9 00:00:25,310 --> 00:00:27,560 And the players must clean this up. 10 00:00:27,560 --> 00:00:34,130 We also have another task where they're going to have to, uh, broom up or clean dirt off of the floor. 11 00:00:34,130 --> 00:00:38,630 So these will be randomly positioned around the floor of our restaurant as well. 12 00:00:38,690 --> 00:00:43,010 We also need to restock the kitchen fridge with food. 13 00:00:43,010 --> 00:00:48,590 So what we'll do is we'll take these crates here and we're going to spawn four of these crates in. 14 00:00:48,590 --> 00:00:50,750 And we're going to rotate them randomly. 15 00:00:50,750 --> 00:00:55,010 And players can grab a can or something from this crate. 16 00:00:55,010 --> 00:00:56,990 And they can walk over and take it. 17 00:00:56,990 --> 00:01:01,340 And there will be a prompt in front of this fridge that the players can go ahead and put their food 18 00:01:01,340 --> 00:01:02,180 inside of. 19 00:01:02,180 --> 00:01:07,460 And then the last task we need to complete is cleaning out the water inside of our toilets. 20 00:01:07,460 --> 00:01:12,650 So each toilet will have some dirty water placed inside of it, and the players must go and clean it 21 00:01:12,650 --> 00:01:15,230 using this toilet scrubber here. 22 00:01:15,680 --> 00:01:20,810 Each of these different tasks have proximity prompts in them inside of these attachments that the players 23 00:01:20,810 --> 00:01:24,410 can use to, you know, go ahead and complete the task. 24 00:01:24,410 --> 00:01:29,510 If at any point the players try to complete a task, but they don't have the necessary tool to complete 25 00:01:29,510 --> 00:01:29,750 it. 26 00:01:29,750 --> 00:01:34,730 So, for example, if they try to clean the dirt on the floor without grabbing the broom, or they try 27 00:01:34,730 --> 00:01:39,200 to clean the toilets without grabbing the toilet brush, or they try to restock the kitchen without 28 00:01:39,200 --> 00:01:44,720 any food on them, we can send a message to them using that update guy event to tell them that they 29 00:01:44,720 --> 00:01:48,890 need a specific tool, or they need something to complete the task correctly. 30 00:01:49,430 --> 00:01:52,730 So let's go ahead and move these back into server storage. 31 00:01:54,510 --> 00:01:59,670 And we also have another folder in here that defines all the possible positions that we could place, 32 00:01:59,670 --> 00:02:05,460 for example, our crumbs, our dirt, the toilet water, and then the positions for these food crates. 33 00:02:05,460 --> 00:02:10,500 So for example, there's these little points on each of the tables that define where we can put the 34 00:02:10,500 --> 00:02:10,980 crumbs at. 35 00:02:10,980 --> 00:02:14,430 So we can put a maximum of six crumb tasks. 36 00:02:14,430 --> 00:02:15,840 Same thing goes for the dirt. 37 00:02:15,840 --> 00:02:19,170 We can place a maximum of six dirt tasks. 38 00:02:19,170 --> 00:02:23,820 There's a maximum of three possible toilet tasks that we can do. 39 00:02:24,240 --> 00:02:27,150 And then we just have four positions for the food crates. 40 00:02:27,150 --> 00:02:32,430 Because the plan is, is that each food crate is going going to have a limited supply of food items 41 00:02:32,430 --> 00:02:32,880 in them. 42 00:02:32,880 --> 00:02:36,900 So for example, maybe there's only three different cans in each crate. 43 00:02:36,900 --> 00:02:41,790 And you need a total of like let's say eight, uh, food items to fill up the fridge, whatever. 44 00:02:42,600 --> 00:02:45,420 That's what we're going to be using those positions for. 45 00:02:45,660 --> 00:02:48,570 So to get started we can open up our task service. 46 00:02:48,570 --> 00:02:51,510 And inside of here we're going to need quite a few services. 47 00:02:51,510 --> 00:02:54,150 We're going to need server script service. 48 00:02:56,340 --> 00:02:59,670 We are going to need server storage. 49 00:03:03,140 --> 00:03:05,690 We are going to need replicated storage. 50 00:03:10,470 --> 00:03:13,320 We will need the player service. 51 00:03:14,670 --> 00:03:19,710 We're going to need a service called the Proximity Prompt Service. 52 00:03:22,880 --> 00:03:25,700 And then we're also going to need the sound service. 53 00:03:28,320 --> 00:03:34,860 Now, what the Proximity prompt service does is it allows for us to listen for when a prompt is activated 54 00:03:34,860 --> 00:03:40,470 in our game, instead of us having to reference prompts directly, we can just use this service which 55 00:03:40,470 --> 00:03:45,540 has an event inside of it that gets fired every single time a prompt gets activated in the game, no 56 00:03:45,540 --> 00:03:47,040 matter what prompt it is. 57 00:03:47,040 --> 00:03:52,260 And then we can check to see if this prompt matches any of the prompts within our tasks item, and then 58 00:03:52,260 --> 00:03:56,130 do whatever according to the specific prompt that was activated. 59 00:03:56,520 --> 00:04:00,630 Next, we can go ahead and create the table that will represent our task service. 60 00:04:01,300 --> 00:04:04,810 And we'll make sure to return it at the end of our script here. 61 00:04:05,410 --> 00:04:08,170 And then now we can make some other variable references. 62 00:04:08,170 --> 00:04:13,990 We need to reference our update guy event, replicated storage, dot events, dot remotes, dot update 63 00:04:13,990 --> 00:04:14,800 guy. 64 00:04:14,800 --> 00:04:18,190 We're going to have to get the guy actions enum. 65 00:04:18,670 --> 00:04:26,170 So we'll require from replicated storage dot modules dot enums, dot guy actions enum. 66 00:04:26,440 --> 00:04:32,830 We'll get the game comms event on the server, so we can call this game comms Bindable. 67 00:04:32,830 --> 00:04:37,360 And that's going to be in server storage, dot events, dot Bindable dot game comms. 68 00:04:37,360 --> 00:04:41,650 And then we can get the game comms enum for the server. 69 00:04:41,650 --> 00:04:49,990 So we'll require that from server script service dot server dot modules, dot enums dot game communication 70 00:04:49,990 --> 00:04:50,560 enum. 71 00:04:50,560 --> 00:04:56,680 And then we're going to get the game comms event replicated storage dot events, dot remotes, dot game 72 00:04:56,680 --> 00:04:57,340 communication. 73 00:04:57,340 --> 00:05:02,110 And then we can get the game comms enum for the client as well. 74 00:05:02,350 --> 00:05:06,940 Replicated storage dot modules dot enums, dot game communication enum. 75 00:05:07,660 --> 00:05:13,960 And then one last event we're going to make a reference to is a another Bindable event in server storage 76 00:05:13,960 --> 00:05:21,040 we're going to call it Tasks Service Bindable which is in server storage, dot events dot Bindesboll's 77 00:05:21,040 --> 00:05:22,420 dot task service Bindable. 78 00:05:22,420 --> 00:05:28,690 And we're going to use this event to listen for when we are told to set up all of the tasks in our game. 79 00:05:28,690 --> 00:05:33,430 So this is going to be the bindable that we need to use to communicate with the service. 80 00:05:34,000 --> 00:05:39,700 And as such, what we could do is we could go into our server script service, go into our game communication 81 00:05:39,700 --> 00:05:44,410 enum, and we can go ahead and create a new section for the task service. 82 00:05:44,410 --> 00:05:49,690 And the actions that we could do in here, for example, is to tell the service to set up tasks. 83 00:05:51,940 --> 00:05:58,600 We could also give the action to disable the task, so this will end it once either our time is up or 84 00:05:58,600 --> 00:06:00,940 we've already completed all of the tasks. 85 00:06:03,020 --> 00:06:10,490 And then we could also give an action to, um, perhaps get some completed task for a particular player, 86 00:06:10,490 --> 00:06:15,560 because later down the road, when the game ends, we want to show the, uh, player how many tasks 87 00:06:15,560 --> 00:06:18,590 they completed, and only the task service is going to know that. 88 00:06:18,590 --> 00:06:24,800 So we can have an action of like get completed tasks for player. 89 00:06:29,140 --> 00:06:33,760 And this could return back to us all of the completed tasks for that particular player. 90 00:06:34,300 --> 00:06:39,460 And that's what we're going to use our task service Bindable for, because this is actually if I retype 91 00:06:39,460 --> 00:06:41,770 it out, this is actually a bindable function. 92 00:06:41,770 --> 00:06:44,260 So we can send information to it. 93 00:06:44,260 --> 00:06:46,600 And we can also get information back. 94 00:06:46,930 --> 00:06:53,050 Now another uh, variable I want to make is to make a reference to a proximity prompt inside of the 95 00:06:53,050 --> 00:06:53,620 workspace. 96 00:06:53,620 --> 00:06:55,510 So we're going to call it referral prompt. 97 00:06:55,510 --> 00:06:57,880 And that's in the workspace dot Krusty Krab. 98 00:06:57,880 --> 00:07:00,070 We'll get the fridge that's in the kitchen. 99 00:07:00,070 --> 00:07:04,570 And then inside of the primary part of the fridge there's an attachment. 100 00:07:05,930 --> 00:07:09,890 And attachment has a proximity prompt inside of it. 101 00:07:09,890 --> 00:07:15,380 So this is the proximity prompt that we're going to use with our fridge to refill it. 102 00:07:15,380 --> 00:07:17,720 So inside of the main body there's an attachment. 103 00:07:17,720 --> 00:07:25,460 And right here is going to be a proximity prompt where we can fulfill it and refill the fridge. 104 00:07:25,760 --> 00:07:29,720 Uh, ensuring that the player actually has food items in their hand. 105 00:07:30,080 --> 00:07:32,630 The next thing I'm going to do is I'm going to create a table. 106 00:07:32,630 --> 00:07:33,740 We'll call it tasks. 107 00:07:33,740 --> 00:07:37,340 And this will store all of the tasks that the players need to complete. 108 00:07:37,670 --> 00:07:40,250 So one of the tasks we'll call it dirt. 109 00:07:40,880 --> 00:07:44,840 And we can give text for this particular task to give to the player. 110 00:07:44,840 --> 00:07:47,990 So this one we need to sweep the floor. 111 00:07:48,140 --> 00:07:53,300 And we're going to put a coin in an empty space here because later we're going to concatenate the string 112 00:07:53,300 --> 00:07:57,500 with how many, um, you know, tasks left they need to do. 113 00:07:57,500 --> 00:08:01,220 So maybe they have three out of 5 or 1 out of two, whatever. 114 00:08:02,020 --> 00:08:05,050 We're going to keep track of whether or not this task was fulfilled. 115 00:08:05,050 --> 00:08:06,490 False is default. 116 00:08:06,490 --> 00:08:11,440 And then we can define whether or not we need a tool to complete this task. 117 00:08:11,440 --> 00:08:17,080 Since we need a broom to sweep the dirt off the floor, we can say, yep, there's a required tool. 118 00:08:17,080 --> 00:08:20,470 And that required tools name is going to be broom. 119 00:08:21,830 --> 00:08:27,380 Lastly, we could also create a key for a completion sound when a player completes the task. 120 00:08:27,380 --> 00:08:31,700 So just to improve the ambience a little bit more, when the player completes this task, we can play 121 00:08:31,700 --> 00:08:33,260 a sound like sweeping. 122 00:08:33,260 --> 00:08:39,050 So inside of the sound service inside of the SFX folder we have a sound called Broom Sweep. 123 00:08:39,050 --> 00:08:41,300 So if we go into the sound service. 124 00:08:42,680 --> 00:08:43,460 Inside of here. 125 00:08:43,460 --> 00:08:45,890 Inside of SFX. 126 00:08:46,500 --> 00:08:48,750 Here is our broom sweep sound. 127 00:08:48,750 --> 00:08:51,810 So when the player completes the broom task, we'll play this. 128 00:08:53,010 --> 00:08:55,470 And we'll do the same thing for when they clean the tables. 129 00:08:55,470 --> 00:08:57,960 When they clean the toilets, we'll play this sound. 130 00:09:00,670 --> 00:09:04,930 And when we want to place an item in the fridge, we can play this sound and some other sounds we have 131 00:09:04,930 --> 00:09:05,830 in here as well. 132 00:09:06,280 --> 00:09:10,570 The next task, for example, is cleaning up crumbs off of the table. 133 00:09:10,750 --> 00:09:15,460 So the text for this one is going to be, uh, wipe the tables. 134 00:09:16,470 --> 00:09:18,630 Fulfilled is going to be false. 135 00:09:18,840 --> 00:09:21,810 There's not going to be any required tool, so we don't have to specify that. 136 00:09:21,810 --> 00:09:24,180 But we do have a completion sound. 137 00:09:24,240 --> 00:09:29,220 And that's going to be the same sound service dot SF dot broom sweep. 138 00:09:29,610 --> 00:09:32,700 The next task that we can do is we'll call it dirty water. 139 00:09:32,700 --> 00:09:34,620 Or this is for our toilets. 140 00:09:34,620 --> 00:09:39,420 So the text for this one is going to be clean the toilets. 141 00:09:40,470 --> 00:09:42,390 Fulfilled is equal to false. 142 00:09:42,390 --> 00:09:44,850 We do have a required tool for this one. 143 00:09:44,850 --> 00:09:46,680 And that's going to be our toilet brush. 144 00:09:46,680 --> 00:09:50,160 So the name of that tool is just toilet brush. 145 00:09:51,110 --> 00:09:58,700 And then we can set the completion sound equal to sound service dot sfx dot toilet flush. 146 00:09:58,820 --> 00:10:02,120 And then the last task is for our food crates. 147 00:10:02,120 --> 00:10:06,950 This one's a little bit special because there's going to be two different things involved with our food 148 00:10:06,950 --> 00:10:07,820 Crate task. 149 00:10:07,820 --> 00:10:12,800 First, the players need to collect an item out of the food crates that will spawn over here, and then 150 00:10:12,800 --> 00:10:18,680 they need to take an item and place it inside of the fridge so we can define the text for this, which 151 00:10:18,680 --> 00:10:19,100 will be. 152 00:10:19,100 --> 00:10:20,450 Stock the kitchen. 153 00:10:21,570 --> 00:10:24,780 Fulfilled also will be false. 154 00:10:25,390 --> 00:10:30,640 Now we're going to have a sound to play when the players collect something out of the crate, so we 155 00:10:30,640 --> 00:10:37,300 can call it collection sound, and that's going to be equal to the sound service SFX, dot crate sound. 156 00:10:37,480 --> 00:10:40,870 And then we're also going to have a completion sound. 157 00:10:41,020 --> 00:10:46,300 So that's going to be sound service dot SFX dot place item in fridge. 158 00:10:46,300 --> 00:10:49,240 After this we're going to create a random data type. 159 00:10:50,030 --> 00:10:54,290 And then I'm also going to make a reference to some other sounds in the sound service. 160 00:10:54,320 --> 00:10:58,640 One is going to store all of the different music that we have for tasks. 161 00:10:58,640 --> 00:11:02,330 So inside of the ambience folder we have a folder called music. 162 00:11:02,330 --> 00:11:05,300 And inside of here we have another folder called Task Music. 163 00:11:05,300 --> 00:11:10,220 And what we could do is we could grab one of these sound instances and play it when the players have 164 00:11:10,220 --> 00:11:11,900 to, you know, go clean up tasks. 165 00:11:11,900 --> 00:11:19,700 So that way we could play music like this, or we could play music like this, or we could play music 166 00:11:19,700 --> 00:11:20,450 like this one. 167 00:11:22,710 --> 00:11:27,000 So we're just going to pick randomly out of the three music instances that we have here. 168 00:11:27,000 --> 00:11:28,050 And we're going to play it. 169 00:11:28,050 --> 00:11:32,550 So we're going to make a reference to all of the different task musics that we have. 170 00:11:32,550 --> 00:11:38,010 So that's going to be in sound service dot ambience, dot music, dot task music. 171 00:11:38,010 --> 00:11:40,050 And we're going to get all the children in there. 172 00:11:40,050 --> 00:11:45,720 And then we can have another variable to keep track of what that chosen music is so chosen music and 173 00:11:45,720 --> 00:11:47,190 we can set it randomly. 174 00:11:47,190 --> 00:11:50,370 So it's going to be equal to task music. 175 00:11:50,670 --> 00:11:53,520 And we're going to get a random one out of there using RNG. 176 00:11:53,520 --> 00:12:00,690 Next integer one to the number of elements inside of our task music table. 177 00:12:00,990 --> 00:12:04,320 And then what I'm also going to do is I'm going to create another table. 178 00:12:04,320 --> 00:12:07,410 And we're going to call this Total tasks. 179 00:12:07,410 --> 00:12:16,140 And this is going to keep track of the current amount of tasks that we have, how many we have fulfilled 180 00:12:16,140 --> 00:12:18,780 and like what's the max amount that we can have. 181 00:12:18,780 --> 00:12:24,150 So for our task for now, I'm just going to set the max equal to one. 182 00:12:24,150 --> 00:12:28,470 The total that we currently have is zero, and the amount that we have fulfilled is zero as well. 183 00:12:28,470 --> 00:12:34,680 And I'm just going to copy this and we can do the same thing for the crumbs. 184 00:12:36,480 --> 00:12:37,140 Paste it again. 185 00:12:37,140 --> 00:12:41,370 We could do the same thing for our dirty water task. 186 00:12:41,370 --> 00:12:45,690 And then one last time we're going to do the same thing for the food crates task. 187 00:12:48,600 --> 00:12:51,660 Now you can of course increase or change these values. 188 00:12:51,660 --> 00:12:56,700 Just make sure they don't exceed, you know, the maximum amount of positions that we have on the map 189 00:12:56,700 --> 00:12:58,020 for the different tasks. 190 00:12:58,020 --> 00:13:03,060 But this table will help us keep track of exactly how many the players have fulfilled. 191 00:13:03,060 --> 00:13:08,220 And then if they, you know, reach the total of fulfilled, then we can tell them that they completed 192 00:13:08,220 --> 00:13:09,690 that particular task. 193 00:13:10,410 --> 00:13:16,500 And the last but not least, we're also going to create a table to keep track of the different totals 194 00:13:16,500 --> 00:13:23,580 for players, so we can call it player task totals, and this will keep track for us the different tasks 195 00:13:23,580 --> 00:13:25,560 that players have completed. 196 00:13:25,560 --> 00:13:28,830 So this will universally keep track of the total tasks completed. 197 00:13:28,830 --> 00:13:31,140 And then this will break it down into different players. 198 00:13:31,140 --> 00:13:33,660 So which player completed what task. 199 00:13:33,660 --> 00:13:35,670 Now some private functions we're going to need. 200 00:13:35,670 --> 00:13:41,100 One is to check the completion of the tasks so we can call it check task completion. 201 00:13:41,100 --> 00:13:42,630 And this will return true or false. 202 00:13:42,630 --> 00:13:48,570 Whether or not we have completed all the tasks, we need a function to listen for when a prompt gets 203 00:13:48,570 --> 00:13:53,310 triggered from our proximity prompt service so we can call it on prompt triggered. 204 00:13:53,400 --> 00:13:55,770 And this function gets passed a prompt instance. 205 00:13:55,770 --> 00:13:57,960 So we can just call it prompt object. 206 00:13:57,960 --> 00:14:01,560 And then it also gets the player that triggered the prompt. 207 00:14:01,560 --> 00:14:03,300 So this is going to be a player. 208 00:14:03,300 --> 00:14:05,700 And then this is going to be a proximity prompt. 209 00:14:06,320 --> 00:14:12,410 We're also going to need a function to listen for when a prompt, you know first gets pressed down so 210 00:14:12,410 --> 00:14:16,070 we can call it on prompt hold began. 211 00:14:16,280 --> 00:14:22,250 This will also get passed a prompt object proximity prompt and it also gets passed a player. 212 00:14:25,380 --> 00:14:29,250 We'll need a function for disabling all of our tasks. 213 00:14:30,020 --> 00:14:34,190 And then we're also going to need a function for setting up our tasks. 214 00:14:34,490 --> 00:14:41,330 Now something important for us to do is we should also make a function for shuffling an array. 215 00:14:41,390 --> 00:14:43,820 So this function can get past an array. 216 00:14:43,820 --> 00:14:48,890 And what it'll do is it'll return back a different array that's completely shuffled. 217 00:14:48,890 --> 00:14:54,320 And what this will do is it'll take the array that is passed to it, and it's going to shuffle it randomly. 218 00:14:54,320 --> 00:15:00,230 So for example, all of the different positions that we have in the map for our different tasks, when 219 00:15:00,230 --> 00:15:04,880 we loop through them and we start setting, you know, our tasks at those different positions. 220 00:15:04,880 --> 00:15:10,940 If the number of tasks that we have set within our table up here, let's say we only set, you know, 221 00:15:10,940 --> 00:15:15,770 there to be two dirt tasks, but we have six positions that we can place the dirt at. 222 00:15:15,770 --> 00:15:21,410 Well, what we want to do is we want to randomly place our dirt tasks at those different positions. 223 00:15:21,410 --> 00:15:26,660 But when we're looping through it, since it's going to be an array, it's always going to set the tasks 224 00:15:26,660 --> 00:15:29,510 at the exact same position every single time. 225 00:15:29,510 --> 00:15:30,050 So. 226 00:15:30,050 --> 00:15:35,570 So what we need to do is we need to shuffle that table that contains the different positions for those 227 00:15:35,570 --> 00:15:41,330 objects, and then we're able to, you know, position our tasks randomly around the map. 228 00:15:41,820 --> 00:15:49,500 Now we're also going to need a function for getting completed tasks of a particular player so we can 229 00:15:49,500 --> 00:15:51,540 call it get completed tasks from. 230 00:15:51,540 --> 00:15:54,360 And we'll pass a player instance to this. 231 00:15:55,980 --> 00:16:00,570 And then we're also going to need a function to listen to our game comms event. 232 00:16:00,570 --> 00:16:06,630 So on game comms event we'll get past an action here. 233 00:16:06,720 --> 00:16:13,140 And then we're also going to need a function to listen to our Bindable function. 234 00:16:13,140 --> 00:16:15,780 So we can call it on Bindable invoke. 235 00:16:15,780 --> 00:16:17,670 And this also gets passed in action. 236 00:16:17,670 --> 00:16:20,070 And then some arguments to go along with that action. 237 00:16:20,550 --> 00:16:27,450 And then for the public functions we're only going to need an initialize function for our task service. 238 00:16:27,450 --> 00:16:31,650 So init what we need to do is we need to listen to our proximity prompt service. 239 00:16:31,650 --> 00:16:33,960 And there's an event in there called prompt triggered. 240 00:16:34,050 --> 00:16:37,020 And this gets triggered when a user interacts with a prompt. 241 00:16:37,020 --> 00:16:40,230 So any prompt in the game will fire this event. 242 00:16:40,230 --> 00:16:43,770 And we can connect our on prompt triggered function. 243 00:16:44,400 --> 00:16:49,440 We're also going to use an event in here called prompt Buttonholed began. 244 00:16:49,440 --> 00:16:53,490 And this is where we will connect our on prompt hold began function. 245 00:16:54,290 --> 00:16:55,970 Inside of the players service. 246 00:16:55,970 --> 00:16:59,600 We're going to be listening to the player removing event. 247 00:16:59,600 --> 00:17:04,010 And the reason we want to do this is because we want to get the player that left the game, and if they 248 00:17:04,010 --> 00:17:09,320 have a key inside of our player task totals table, then we want to remove them from that table. 249 00:17:09,980 --> 00:17:16,100 We'll want to listen to our Game Comms Bindable dot event, and we'll connect our on game comms event 250 00:17:16,100 --> 00:17:16,880 function. 251 00:17:16,880 --> 00:17:20,810 And then we want to listen to our tasks service Bindable. 252 00:17:21,450 --> 00:17:27,060 And then for the on invoke property, we can set that equal to the on Bindable invoke function. 253 00:17:27,720 --> 00:17:32,910 So let's go ahead and fill out, uh, our on game comms event function. 254 00:17:32,910 --> 00:17:33,630 Why not? 255 00:17:33,930 --> 00:17:42,630 So inside of here, the two actions we want to listen to is inside of game comms enum server dot task 256 00:17:42,630 --> 00:17:45,330 service dot setup tasks. 257 00:17:45,330 --> 00:17:49,590 So when we are told to set up tasks then we can call our setup task function. 258 00:17:50,420 --> 00:17:56,990 Otherwise, if our action is equal to game comms enum server task service dot disable tasks, then we 259 00:17:56,990 --> 00:17:59,450 can call our disable tasks function. 260 00:17:59,750 --> 00:18:02,510 So let's go ahead and fill out our setup tasks function. 261 00:18:02,990 --> 00:18:09,110 Inside of here what we need to do is we need to loop through every single location or possible task 262 00:18:09,110 --> 00:18:14,300 location inside of a server storage dot task part positions. 263 00:18:14,300 --> 00:18:16,460 And we're going to get all of the children in there. 264 00:18:18,470 --> 00:18:24,080 And now, since there's four separate folders for different task locations, then that means we're going 265 00:18:24,080 --> 00:18:26,720 to have to loop through each one of those different folders. 266 00:18:26,720 --> 00:18:29,630 So we're getting past four folders in this for loop. 267 00:18:29,630 --> 00:18:37,820 So we're going to loop through every single position inside of that task location folder get children. 268 00:18:37,820 --> 00:18:42,440 So we're looping through this folder right here which gives us four different folders. 269 00:18:42,440 --> 00:18:47,630 And then we're looping through each one of these folders to get to the different positions. 270 00:18:47,630 --> 00:18:53,660 Now as I said, it's important that we shuffle this table right here because we're always going to be 271 00:18:53,660 --> 00:18:56,510 return an array starting from the top to the bottom. 272 00:18:56,510 --> 00:19:02,240 So if we want to randomly place our tasks around the map, we need to go ahead and make this array, 273 00:19:02,240 --> 00:19:03,680 you know, random. 274 00:19:03,680 --> 00:19:08,630 So what we could do is we could call our shuffle function here and pass this table to it. 275 00:19:08,630 --> 00:19:12,050 And this will return back to us an array that is shuffled. 276 00:19:12,850 --> 00:19:14,380 Now inside of the shuffle function. 277 00:19:14,380 --> 00:19:18,220 What we need to do is we need to loop through every single index value pair in our array. 278 00:19:18,220 --> 00:19:24,760 So we'll start the index at one, and we'll loop all the way to the length of our array minus one. 279 00:19:24,760 --> 00:19:29,590 Because what we're going to be doing is we're going to be swapping positions of values in the table 280 00:19:29,590 --> 00:19:30,310 randomly. 281 00:19:30,310 --> 00:19:35,830 So we don't need to go to the very last one, because when we swap two different positions, it's also 282 00:19:35,830 --> 00:19:39,340 going to include that last value, which is why we're subtracting it by one here. 283 00:19:39,340 --> 00:19:42,220 And what we're going to do is we're going to generate a random number. 284 00:19:42,220 --> 00:19:46,510 So we'll call it random index equal to RNG next integer. 285 00:19:46,510 --> 00:19:50,800 And we're going to pass one and get the length of our array. 286 00:19:51,550 --> 00:19:56,890 And then we're also going to get the value that is currently stored within our array at the index we're 287 00:19:56,890 --> 00:19:58,600 at in this for loop. 288 00:19:58,960 --> 00:20:04,600 Because now what we're going to do is we're going to set inside of our array at the current index. 289 00:20:04,600 --> 00:20:10,300 We're going to set it equal to whatever value is stored inside of our array at this random index. 290 00:20:10,300 --> 00:20:17,530 And then once we do that at our random index, we're going to set it equal to the value that we just 291 00:20:17,530 --> 00:20:18,250 stored here. 292 00:20:18,250 --> 00:20:24,730 So you can basically think of us randomly swapping the values, uh inside of our array. 293 00:20:24,730 --> 00:20:29,080 And then once we're done with that, we can go ahead and return the array at the end. 294 00:20:29,680 --> 00:20:35,590 So basically if we passed a table like one, two, three and four, this is going to loop through each 295 00:20:35,590 --> 00:20:35,950 value. 296 00:20:35,950 --> 00:20:38,860 And it's going to randomly swap the positions of these values. 297 00:20:38,860 --> 00:20:46,090 So we might get an output that's completely different like 312 and four something like that. 298 00:20:46,090 --> 00:20:49,300 That's the whole purpose of our nice little shuffle function here. 299 00:20:49,300 --> 00:20:56,410 So now that we got this shuffled array, what we can do is we first want to check inside of our total 300 00:20:56,410 --> 00:20:57,670 task table. 301 00:20:57,670 --> 00:21:02,290 We're going to pass this task locations name which matches what we have in the table. 302 00:21:02,290 --> 00:21:04,390 And we're going to check the total. 303 00:21:04,390 --> 00:21:09,760 And if this total is greater than or equal to total tasks. 304 00:21:09,760 --> 00:21:14,050 Task location dot name dot max. 305 00:21:14,050 --> 00:21:19,630 So if we're already at the max amount of tasks for this particular position, then we're just going 306 00:21:19,630 --> 00:21:23,710 to break out of this for loop and move to the next task location. 307 00:21:24,610 --> 00:21:30,100 Otherwise, what we're going to do is we're going to create a clone of the task object we need to fulfill 308 00:21:30,100 --> 00:21:31,090 at this position. 309 00:21:31,090 --> 00:21:38,380 So inside of server storage dot task parts, we're going to pass the task location dot name. 310 00:21:38,380 --> 00:21:43,510 So we're getting whatever task part based on the name of the location. 311 00:21:43,690 --> 00:21:45,820 And then we're going to clone it. 312 00:21:46,900 --> 00:21:53,290 Then we can set the position of this clone equal to the position of our part. 313 00:21:55,080 --> 00:22:01,530 Now if this task location dot name is not equal to dirty water. 314 00:22:02,050 --> 00:22:07,270 Then what we want to do is we want to randomly rotate it so it's not always the same, right? 315 00:22:07,270 --> 00:22:11,260 We don't want to make it look like we copy and pasted the same task all over the place, but if we rotate 316 00:22:11,260 --> 00:22:16,690 it randomly, then it makes it look a little bit nicer, so we can get our clone and we can change the 317 00:22:16,690 --> 00:22:20,740 rotation to be equal to a vector three dot new. 318 00:22:20,740 --> 00:22:29,350 For the x axis we don't care, but for the y axis we can do rng next integer and rotate it randomly 319 00:22:29,350 --> 00:22:33,370 360 degrees and then zero for the z axis. 320 00:22:34,030 --> 00:22:39,520 And then afterwards, we can set the parent of our clone equal to the workspace Krusty Krab. 321 00:22:39,520 --> 00:22:41,500 And there's a folder in there called tasks. 322 00:22:41,500 --> 00:22:47,110 And now that we've placed it on the map, we want to update the total value inside of our Total tasks 323 00:22:47,110 --> 00:22:47,620 table. 324 00:22:47,620 --> 00:22:52,870 So we'll just copy this and set the total plus equal to one. 325 00:22:52,870 --> 00:22:58,720 Then what we could do is we could use our update guy event and fire to all of the clients that they 326 00:22:58,720 --> 00:23:03,490 need to do the GUI actions enum of update tasks. 327 00:23:03,490 --> 00:23:09,220 So we're going to be adding a whole bunch of tasks to their GUI, and we're going to have to pass a 328 00:23:09,220 --> 00:23:09,730 table. 329 00:23:09,730 --> 00:23:15,460 And inside of this table we need different tables to represent each of the different tasks. 330 00:23:15,460 --> 00:23:16,090 Right. 331 00:23:18,340 --> 00:23:23,740 So up here, this first task that we could pass the name of this one is going to be dirt, because it's 332 00:23:23,740 --> 00:23:24,760 the dirt task. 333 00:23:24,760 --> 00:23:28,690 And the text for this task is going to be inside of the tasks. 334 00:23:28,690 --> 00:23:31,990 Dot dirt, dot text. 335 00:23:32,830 --> 00:23:37,480 And then we're going to concatenate this with the total tasks dot dirt. 336 00:23:38,520 --> 00:23:40,140 And get the fulfilled number. 337 00:23:40,140 --> 00:23:46,800 And then we can concatenate that with a slash and then concatenate that with the total task dot dirt 338 00:23:46,800 --> 00:23:47,790 dot total. 339 00:23:47,790 --> 00:23:50,580 So how many have we fulfilled out of the total. 340 00:23:50,580 --> 00:23:54,720 And then we could just basically do this exact same thing for the other tasks. 341 00:23:54,720 --> 00:23:57,300 So we'll just paste this in here four times. 342 00:23:57,300 --> 00:24:00,840 We'll change this one to the crumbs task. 343 00:24:00,840 --> 00:24:04,680 This will be tasks dot crumbs dot text. 344 00:24:05,570 --> 00:24:10,550 And we'll get the amount that we have fulfilled for the crumbs and then the total. 345 00:24:11,340 --> 00:24:15,690 We'll do the same thing for the dirty water or toilet task. 346 00:24:16,260 --> 00:24:17,640 So tasked. 347 00:24:17,640 --> 00:24:18,900 Dirty water. 348 00:24:19,650 --> 00:24:21,690 And then here we got to do the same thing. 349 00:24:21,690 --> 00:24:22,860 Dirty water. 350 00:24:25,550 --> 00:24:27,170 Now for our food crates. 351 00:24:27,170 --> 00:24:34,940 It's going to be a little bit different, and that's because we do not want to update the total for 352 00:24:34,940 --> 00:24:37,610 this task based on how many crates are on the map. 353 00:24:37,610 --> 00:24:45,230 Instead, we want the max value here to represent how many cans of food we need to put inside of the 354 00:24:45,230 --> 00:24:46,250 fridge here. 355 00:24:46,550 --> 00:24:49,070 So basically what we need to do. 356 00:24:49,740 --> 00:24:59,310 Is we need to set the total tasks dot food crates dot total equal to the total tasks dot food crates 357 00:24:59,310 --> 00:25:00,720 dot max value. 358 00:25:00,720 --> 00:25:07,800 Because the max value is going to define for us how many food items we need to put in the fridge, instead 359 00:25:07,800 --> 00:25:09,780 of how many food crates we need to put on the map. 360 00:25:09,780 --> 00:25:12,300 Because we're always going to put four food crates on the map. 361 00:25:12,300 --> 00:25:18,030 But this number here reflects how many different items out of those crates that we have to put into 362 00:25:18,030 --> 00:25:19,080 our fridge. 363 00:25:19,080 --> 00:25:25,290 Now we can go ahead and pass food crates as the name for this one. 364 00:25:26,450 --> 00:25:30,050 And then, of course, we're going to have to get the task for the food crates. 365 00:25:31,300 --> 00:25:38,530 And then we'll pass the fulfilled slash food crates dot total. 366 00:25:38,770 --> 00:25:45,820 So once we have set up all of the tasks, and then we have added the tasks to the player's GUI, the 367 00:25:45,820 --> 00:25:52,630 last thing we need to do is use our game comms event and fire to all of the clients using the game comms 368 00:25:52,660 --> 00:25:56,440 enum client dot two client dot play sound. 369 00:25:56,440 --> 00:26:00,070 And the sound that we're going to play is going to be the music. 370 00:26:00,070 --> 00:26:06,100 So we're going to pass the chosen music and then play at point is going to be equal to false, because 371 00:26:06,100 --> 00:26:10,510 we want to play it universally for all the players, and we don't want it to emanate from a specific 372 00:26:10,510 --> 00:26:11,020 point. 373 00:26:11,440 --> 00:26:15,160 So let's actually go ahead and test out what we've gotten done here so far. 374 00:26:15,160 --> 00:26:19,510 Specifically, I want to make sure that our setup tasks function is working correctly. 375 00:26:19,510 --> 00:26:24,760 So when we are told to set up tasks, we're going to call this function, which means we can go back 376 00:26:24,760 --> 00:26:27,820 to our game section module script here. 377 00:26:27,940 --> 00:26:32,110 And we can go back down for when we're starting section one of the game. 378 00:26:32,110 --> 00:26:38,200 And then after the player's ad, you know the tasks objective to their screen. 379 00:26:38,200 --> 00:26:44,770 Then we want to use the game comms event on the server or the Bindable. 380 00:26:44,770 --> 00:26:51,460 And we want to fire using the Game Comms enum server action for the task service. 381 00:26:51,460 --> 00:26:55,090 And we want to let the task service know that it needs to set up all the tasks. 382 00:26:55,240 --> 00:26:57,640 So if we go and play our game. 383 00:27:01,660 --> 00:27:05,410 And we'll wait for all of this stuff to go by real quick. 384 00:27:06,250 --> 00:27:11,350 So once this text goes away, we should get the task system set up. 385 00:27:13,050 --> 00:27:14,070 And there we go. 386 00:27:14,430 --> 00:27:16,080 So now we're having the music played. 387 00:27:16,080 --> 00:27:18,540 As you can see, the task updated on the screen. 388 00:27:18,540 --> 00:27:22,080 Sweep the floor, wipe the tables, clean the toilets and stock the kitchen. 389 00:27:22,080 --> 00:27:25,470 And as you can see, our tasks were randomly placed on the map here. 390 00:27:25,470 --> 00:27:28,830 So for example, here's the one table we need to clean. 391 00:27:28,830 --> 00:27:31,500 Here's the thing that we need to sweep on the floor. 392 00:27:31,770 --> 00:27:34,110 And then we also got food placed here. 393 00:27:35,100 --> 00:27:39,960 Um, unfortunately it looks like we only got one of these food item plates. 394 00:27:39,960 --> 00:27:43,080 And I think that's because of a little bit of a logical error in our for loop. 395 00:27:43,080 --> 00:27:44,910 So we'll have to fix that in a little bit. 396 00:27:46,080 --> 00:27:50,640 And then if we go inside of the bathroom we should have here we go. 397 00:27:50,640 --> 00:27:53,280 One of our toilet tasks as well set up. 398 00:27:53,280 --> 00:27:59,070 Now regarding that issue we have where we're not getting all of the crates placed on the map. 399 00:27:59,370 --> 00:28:04,320 Uh, I think the issue is because we're prematurely breaking out of this for loop here, because we're 400 00:28:04,320 --> 00:28:09,630 updating the total for every single task, including the food crates task, which we don't want to do. 401 00:28:09,780 --> 00:28:14,280 So before we actually update the total here, what we could do is we could have an if statement and 402 00:28:14,280 --> 00:28:18,660 make sure that the task location dot name is not equal to food crates. 403 00:28:18,660 --> 00:28:24,000 That way we can actually place all of the food crates that we need on the map that are specified by 404 00:28:24,000 --> 00:28:28,470 the four positions we've set there, so that should fix our food crate problem. 405 00:28:28,980 --> 00:28:33,330 The next thing we want to script is giving players the ability to actually interact with the prompts 406 00:28:33,330 --> 00:28:34,470 of the tasks. 407 00:28:34,970 --> 00:28:39,980 So for example, we can go ahead and fill out our on prompt hold began function. 408 00:28:39,980 --> 00:28:47,630 And what we could do is we could get the object from this prompt so we can call it task object. 409 00:28:47,630 --> 00:28:52,520 And that should be equal to the prompt object dot parent dot parent. 410 00:28:52,880 --> 00:28:53,420 Right. 411 00:28:53,420 --> 00:28:58,910 Since our proximity prompt is in an attachment, the parent is going to be of course the attachment. 412 00:28:58,910 --> 00:29:02,750 And then the parent of the attachment is going to be the task object itself. 413 00:29:02,750 --> 00:29:09,320 From this point, we can check if the task object dot name is equal to something like the dirt task, 414 00:29:09,320 --> 00:29:14,360 because we want to make sure that the player actually has the proper tool to fulfill this task. 415 00:29:14,360 --> 00:29:23,750 We can also do the same for the task object dot name, and this one's going to be the dirty water task. 416 00:29:24,830 --> 00:29:27,530 Because we're checking the name of the task object. 417 00:29:27,530 --> 00:29:32,510 Any other prompts in our game that get triggered or have this function called on them will be ignored 418 00:29:32,510 --> 00:29:34,910 because they get skipped by our if statements here. 419 00:29:35,430 --> 00:29:41,070 Now, if our task object is going to be the dirt task, then we're going to get the tool that's currently 420 00:29:41,070 --> 00:29:42,510 on their character. 421 00:29:42,510 --> 00:29:47,340 So we can do player dot character find first child, which is a tool. 422 00:29:47,700 --> 00:29:51,930 And we need to check if this tool matches the tool required for this task. 423 00:29:51,930 --> 00:29:59,370 So if they don't have a tool on their character, or let's say the tool on their character is not equal 424 00:29:59,370 --> 00:30:01,680 to the one specified within our tasks table. 425 00:30:01,680 --> 00:30:07,620 So we can pass task object dot name and then get the required tool for this task. 426 00:30:09,240 --> 00:30:13,110 If it's not matching, then we can update this player. 427 00:30:13,760 --> 00:30:19,130 So Fhir client and we're going to pass this player GUI actions enum. 428 00:30:19,280 --> 00:30:23,180 And then we're going to do the small message and we're going to tell them. 429 00:30:24,300 --> 00:30:27,120 That you need a broom. 430 00:30:27,810 --> 00:30:32,580 For this task, and then we'll make sure to return out of the function. 431 00:30:32,910 --> 00:30:36,900 And then we can just basically copy this and then paste this here. 432 00:30:37,260 --> 00:30:40,560 And let me make sure to rename this to Dirty Water. 433 00:30:40,590 --> 00:30:42,630 It's very important to match the strings. 434 00:30:42,990 --> 00:30:49,380 And after we check the tool here we want to make sure to change the text to tell them that they need 435 00:30:49,380 --> 00:30:53,640 a toilet brush for this task. 436 00:30:53,640 --> 00:30:55,980 And that's all we need to do for this function. 437 00:30:56,280 --> 00:31:00,180 Now inside of our on prompt triggered function we're going to do the same thing. 438 00:31:00,180 --> 00:31:05,430 We're going to get the task object from the prompt object dot parent dot parent. 439 00:31:05,760 --> 00:31:11,730 And the first thing what we want to do is we want to check if this player has a key within the player 440 00:31:11,730 --> 00:31:12,900 task totals table. 441 00:31:12,900 --> 00:31:14,310 So if they don't. 442 00:31:14,310 --> 00:31:19,380 So inside of player task totals, if we pass their name and they don't have a key in there, then we 443 00:31:19,380 --> 00:31:20,610 need to set one up for them. 444 00:31:20,610 --> 00:31:22,350 So we'll copy this. 445 00:31:22,470 --> 00:31:25,260 And what we could do is we could set a table for them. 446 00:31:25,260 --> 00:31:30,870 And in here it's going to store how many dirt tasks they completed, how many crumbs tasks they completed, 447 00:31:30,870 --> 00:31:36,750 how many dirty water tasks they completed, and then how many food crates tasks they completed. 448 00:31:36,750 --> 00:31:43,320 From this point, we're going to check if the task object dot name is equal to food crates. 449 00:31:43,320 --> 00:31:49,350 So if they trigger the prompt inside of the food crates, then we need to give them, you know, a food 450 00:31:49,350 --> 00:31:50,310 object. 451 00:31:50,310 --> 00:31:55,080 Now the first thing we need to check on this food crate is whether or not it has enough stock. 452 00:31:55,080 --> 00:31:59,790 So if we actually go inside of server storage and we check our food crates, there's some attributes 453 00:31:59,790 --> 00:32:05,400 in here that tells us how much stock is left in the crate and the max stock for the crate. 454 00:32:05,400 --> 00:32:10,410 So if this task object get attribute stock left. 455 00:32:11,360 --> 00:32:15,350 Is equal to zero, then we're just going to return out of this function because we don't care about 456 00:32:15,350 --> 00:32:16,280 this prompt. 457 00:32:16,930 --> 00:32:22,630 Otherwise, if they aren't out of stock, then we're just going to check to see whether or not a player 458 00:32:22,630 --> 00:32:25,150 already has a food item tool on them. 459 00:32:25,150 --> 00:32:29,110 So inside of the player's backpack we're going to find First Child. 460 00:32:29,110 --> 00:32:31,600 And the name for this tool is called food. 461 00:32:31,600 --> 00:32:35,680 So if they already have it in their backpack or they're already holding one. 462 00:32:35,680 --> 00:32:40,030 So player dot character find first child food. 463 00:32:40,480 --> 00:32:47,500 So if they already have this tool then we're just going to use the update guy event and tell this player 464 00:32:47,500 --> 00:32:50,650 that, hey, you can't grab any more stock because you're already holding some. 465 00:32:50,650 --> 00:32:58,120 So we can do guy actions enum dot small message and give them a message like you already have food on 466 00:32:58,150 --> 00:33:02,560 you and then we can return because we don't care about that either. 467 00:33:02,560 --> 00:33:05,290 Otherwise if they don't have the tool then we need to give it to them. 468 00:33:05,290 --> 00:33:10,000 So first we're going to use our game comms event and fire to all the clients to play a sound. 469 00:33:10,000 --> 00:33:14,830 So game comms enum client dot two client dot play sound. 470 00:33:14,830 --> 00:33:18,940 And the sound we want to play is going to be equal to the tasks. 471 00:33:18,940 --> 00:33:21,610 We're going to pass the task object dot name. 472 00:33:21,730 --> 00:33:28,300 And then we're going to get the collection sound play at point. 473 00:33:28,570 --> 00:33:30,610 We're going to set that to be true. 474 00:33:30,880 --> 00:33:36,070 And the position we want to play it at is going to be equal to the task object dot position. 475 00:33:37,960 --> 00:33:40,720 The next thing we could do is inside of the task object. 476 00:33:40,720 --> 00:33:44,170 We can set the attribute of stock left. 477 00:33:44,890 --> 00:33:48,310 Equal to the task object. 478 00:33:48,310 --> 00:33:53,560 Get attribute stock left and we're going to subtract this by one. 479 00:33:53,560 --> 00:33:58,420 So actually uh what we could do is we could store the stock left in a variable. 480 00:33:58,420 --> 00:34:00,790 So stock left is equal to. 481 00:34:01,650 --> 00:34:05,490 We'll copy this, paste that here, and then we can just copy the name of this variable and compare 482 00:34:05,490 --> 00:34:06,360 it here. 483 00:34:07,550 --> 00:34:11,480 And then we'll just paste that here. 484 00:34:11,510 --> 00:34:15,080 So we're reducing the stock on our task object. 485 00:34:15,080 --> 00:34:19,580 And then we're going to update the object text within our proximity prompt. 486 00:34:19,610 --> 00:34:24,890 So prompt object dot object text. 487 00:34:24,890 --> 00:34:29,120 We're going to set it equal to food left. 488 00:34:29,960 --> 00:34:32,750 And we can concatenate this with the updated stock. 489 00:34:32,750 --> 00:34:37,580 So task object get attribute stock left. 490 00:34:37,580 --> 00:34:46,340 Concatenate that with a slash and then concatenate that with the task object get attribute max stock. 491 00:34:48,310 --> 00:34:53,020 Because inside of our fruit crates and inside of the attachments, there will be a string in there that 492 00:34:53,020 --> 00:34:57,970 tells us how much food is left, and we need to update it every single time a player grabs food out 493 00:34:57,970 --> 00:34:58,510 of it. 494 00:34:58,540 --> 00:35:02,020 After that, we can get a clone of this tool we need. 495 00:35:02,020 --> 00:35:09,340 So in server storage and the tools folder dot tasks, there's a food tool. 496 00:35:09,340 --> 00:35:11,050 We're going to clone that. 497 00:35:11,290 --> 00:35:13,840 And then we're going to give it to the player. 498 00:35:13,840 --> 00:35:16,570 So player dot backpack. 499 00:35:16,660 --> 00:35:23,620 The next prompt we need to specifically listen for is to see if the prompt object is equal to our refill 500 00:35:23,620 --> 00:35:24,610 prompt. 501 00:35:24,610 --> 00:35:28,870 Or basically this player has gone up to the fridge and activated the refill prompt. 502 00:35:28,870 --> 00:35:31,840 So we need to check if they actually have food on them. 503 00:35:31,840 --> 00:35:34,690 So we're going to check to see if they're holding it. 504 00:35:34,690 --> 00:35:40,450 So player dot character find first child food. 505 00:35:41,190 --> 00:35:47,880 If they do not have a food tool, then we're going to use the update GUI event and fire to this particular 506 00:35:47,880 --> 00:35:48,720 player. 507 00:35:49,230 --> 00:35:56,130 And we're going to give them a message, and we're going to tell them you have nothing to restock with. 508 00:35:56,340 --> 00:35:58,050 You have nothing at all. 509 00:35:58,140 --> 00:36:00,090 And then we're going to return. 510 00:36:00,390 --> 00:36:03,600 Otherwise we can use our game comms event. 511 00:36:04,500 --> 00:36:07,830 And we can fire to all the clients in the game to play another sound. 512 00:36:07,830 --> 00:36:12,180 So game comms enum for the client two client play sound. 513 00:36:12,630 --> 00:36:15,660 The sound for this one is going to be equal to tasks. 514 00:36:15,660 --> 00:36:19,200 Dot food crates dot completion sound. 515 00:36:20,000 --> 00:36:21,170 Play at. 516 00:36:22,120 --> 00:36:29,350 Point is going to be true, and the position is going to be equal to the task object dot position. 517 00:36:30,870 --> 00:36:34,170 And then we can destroy this tool out of the players hands. 518 00:36:34,170 --> 00:36:40,470 And then we want to set total tasks dot food crates dot fulfilled plus equal to one. 519 00:36:40,830 --> 00:36:45,690 And then for this particular player we want to, you know give them the credit for completing this task. 520 00:36:45,690 --> 00:36:49,170 So player task totals will pass the player dot name. 521 00:36:49,260 --> 00:36:55,380 And we'll get their food crates and set that equal plus equal to one. 522 00:36:55,770 --> 00:37:02,520 Now each time a food task is completed, we need to check whether or not that we have reached, you 523 00:37:02,520 --> 00:37:06,150 know, the total amount of food crate tasks we need to complete. 524 00:37:06,150 --> 00:37:15,000 So if total tasks dot food crates dot fulfilled is equal to total tasks dot food crates dot total. 525 00:37:16,620 --> 00:37:21,300 Then we're going to set the refill prompt dot enabled equal to false. 526 00:37:21,660 --> 00:37:27,210 And then we're going to use the update GUI event and fire to all of the clients that we fulfilled a 527 00:37:27,210 --> 00:37:27,690 task. 528 00:37:27,690 --> 00:37:30,660 So GUI actions enum dot task fulfilled. 529 00:37:31,300 --> 00:37:36,850 And the fulfilled task is going to be our food crates task. 530 00:37:38,030 --> 00:37:42,560 And we can set the text for that one to be equal to the task. 531 00:37:42,560 --> 00:37:44,780 Dot food crates dot text. 532 00:37:45,390 --> 00:37:53,610 And then the total tasks dot food crates dot fulfilled will concatenate that with a slash and then concatenate 533 00:37:53,610 --> 00:37:55,050 that with the total tasks. 534 00:37:55,050 --> 00:37:57,030 Dot food crates dot total. 535 00:37:58,040 --> 00:38:04,520 So this will make that task on the screen appear green, and then it'll update it with the new amount. 536 00:38:04,520 --> 00:38:08,630 So if we fulfilled three out of three, that's what it'll display on the screen. 537 00:38:10,660 --> 00:38:16,420 Otherwise, if we didn't, uh, fulfill the task, we still need to update the task on the client side 538 00:38:16,420 --> 00:38:19,750 to stay consistent with the tasks that have been completed. 539 00:38:19,750 --> 00:38:27,700 So we're just going to copy this, but instead we're going to give them the action of update task. 540 00:38:27,700 --> 00:38:29,620 So we need to update a specific task. 541 00:38:29,620 --> 00:38:33,130 And that task to update is food crates. 542 00:38:33,130 --> 00:38:35,770 And we're just updating the text for that one as well. 543 00:38:36,100 --> 00:38:36,580 Okay. 544 00:38:36,580 --> 00:38:43,000 So now that we have made these two specific special checks just for our food crates task, what we can 545 00:38:43,000 --> 00:38:48,220 do here is just create an if statement for every other single task. 546 00:38:48,220 --> 00:38:53,500 So if this, uh, task object is inside of our total task table. 547 00:38:53,500 --> 00:38:55,960 So we're going to pass the task objectname. 548 00:38:55,960 --> 00:39:03,100 If there's a key inside of that table, then what we need to do is we need to check if tasks task Objectname 549 00:39:03,280 --> 00:39:05,920 has a required tool. 550 00:39:06,950 --> 00:39:13,430 If they do, then we need to check if this tool is on the player's character or they have it equipped. 551 00:39:13,430 --> 00:39:17,390 So player character find first child, which is a tool. 552 00:39:18,240 --> 00:39:25,590 If they do not have a tool on our character, or the tool on the character name is not equal to the 553 00:39:25,590 --> 00:39:28,800 task's task object. 554 00:39:28,800 --> 00:39:32,610 Dot name dot required tool. 555 00:39:33,680 --> 00:39:39,200 Then we need to use the update UI event and fire to this particular player that they cannot complete 556 00:39:39,200 --> 00:39:39,860 the task. 557 00:39:39,860 --> 00:39:47,720 So GUI actions dot small message, and the message we're going to give them is you do not have the required 558 00:39:47,720 --> 00:39:52,070 tool needed to complete this task. 559 00:39:53,490 --> 00:39:56,640 Otherwise we can set total tasks. 560 00:39:56,640 --> 00:40:03,000 Pass task Objectname dot fulfilled plus equal one. 561 00:40:03,580 --> 00:40:05,650 And then we also got to give him credit for it as well. 562 00:40:05,650 --> 00:40:10,060 So task totals pass the player name. 563 00:40:10,060 --> 00:40:13,630 And then we're also going to pass here the task object dot name. 564 00:40:13,630 --> 00:40:17,200 And then we'll set that plus equal to one as well. 565 00:40:17,200 --> 00:40:20,860 And then we need to check if this particular task has a completion sound. 566 00:40:20,860 --> 00:40:27,970 So if tasks pass task object dot name dot completion sound then we need to use the game comms event 567 00:40:27,970 --> 00:40:30,040 and fire to all the clients to play a sound. 568 00:40:30,040 --> 00:40:34,360 So game comms enum client dot two client dot play sound. 569 00:40:35,620 --> 00:40:38,290 The sound is going to be equal to the tasks. 570 00:40:38,560 --> 00:40:40,540 Task object dot name. 571 00:40:41,110 --> 00:40:44,890 And that's going to be the completion sound. 572 00:40:44,920 --> 00:40:48,760 We can set play at point equal to true. 573 00:40:48,760 --> 00:40:54,130 And the point is going to be equal to the task object dot position. 574 00:40:56,310 --> 00:41:03,960 Afterwards, we can have another if statement to check whether or not, um, this task was fulfilled. 575 00:41:03,960 --> 00:41:10,620 So if total tasks task object dot name dot fulfilled. 576 00:41:11,750 --> 00:41:14,090 Is equal to the total tasks task. 577 00:41:14,090 --> 00:41:18,650 Objectname yeah, I know this is getting pretty redundant, but total. 578 00:41:18,650 --> 00:41:23,930 So if we completed all the tasks necessary, then we can use the update UI event and tell them that 579 00:41:23,930 --> 00:41:25,130 they fulfilled the task. 580 00:41:25,130 --> 00:41:28,460 So I'm just going to copy this up here real quick. 581 00:41:28,940 --> 00:41:30,530 And we can paste that here. 582 00:41:30,530 --> 00:41:36,290 And the fulfill task is going to be equal to the task Objectname. 583 00:41:36,770 --> 00:41:47,000 And then the text is going to be equal to tasks pass task objects and then get the text. 584 00:41:48,270 --> 00:41:52,020 And then we'll just copy this and paste that here. 585 00:41:52,760 --> 00:41:55,670 Not fulfilled and then paste that here as well. 586 00:41:56,950 --> 00:42:02,170 Otherwise, if we didn't fulfill the task, then we can just do the exact same thing, but instead we 587 00:42:02,170 --> 00:42:04,060 need to update the task. 588 00:42:04,180 --> 00:42:05,410 So. 589 00:42:06,110 --> 00:42:07,610 Update task. 590 00:42:08,660 --> 00:42:13,280 Task to update and we should be good to go there. 591 00:42:13,400 --> 00:42:18,500 And then after we have completed this particular task object, we need to go ahead and destroy it off 592 00:42:18,500 --> 00:42:18,920 the map. 593 00:42:18,920 --> 00:42:22,370 So task object destroy. 594 00:42:23,350 --> 00:42:33,220 After all of that, the last thing we need to check is if we have completed all of the tasks in our 595 00:42:33,220 --> 00:42:33,910 game. 596 00:42:33,910 --> 00:42:39,370 So if we call our check task completion function and that returns true. 597 00:42:40,280 --> 00:42:49,670 Then we can use the game, combined a ball and fire to let our game section function know that all of 598 00:42:49,670 --> 00:42:56,120 the tasks have been completed, and this function can continue on executing because the plan is is that 599 00:42:56,120 --> 00:43:02,390 once we tell the task service to set up tasks, this is going to sit here and yield until either we 600 00:43:02,390 --> 00:43:09,650 reach a timeout or we get a message back from the task service telling us that all the tasks have been 601 00:43:09,650 --> 00:43:17,660 completed so we can fire and pass the game comms enum server, and we can create a key for our game 602 00:43:17,660 --> 00:43:18,350 service. 603 00:43:18,350 --> 00:43:24,230 So inside of the game Communication enum, I'll create a new section for game service. 604 00:43:24,230 --> 00:43:29,030 And in here we can give them the action that we completed all of the tasks. 605 00:43:32,610 --> 00:43:35,490 So game service not completed tasks. 606 00:43:35,520 --> 00:43:40,770 Now, something that's important to note is that if you remember, this function is going to get called 607 00:43:40,770 --> 00:43:44,340 every single time a player interacts with a proximity prompt in our game. 608 00:43:44,340 --> 00:43:46,020 Doesn't matter what the prompt is. 609 00:43:46,020 --> 00:43:53,880 So we need to ensure that this particular prompt is actually equal to a task object prompt or our Re-fill 610 00:43:53,880 --> 00:44:00,480 prompt, because we don't want to keep, you know, firing this event every single time that this function 611 00:44:00,480 --> 00:44:03,720 gets called, even after all of our tasks have been completed. 612 00:44:03,720 --> 00:44:09,390 So we need to ensure that inside of our tasks table, there is a key for this task object dot name. 613 00:44:09,780 --> 00:44:14,790 Or we need to make sure that this prompt object is equal to our Re-fill prompt. 614 00:44:14,790 --> 00:44:18,690 And then we also need to make sure that we have completed all of our tasks. 615 00:44:18,690 --> 00:44:21,780 If so, then we can go ahead and fire this Bindable. 616 00:44:21,780 --> 00:44:24,900 Now let's go ahead and fill out our check task completion function real quick. 617 00:44:24,900 --> 00:44:29,010 And this one should be relatively easy to do, because all we're going to do is we're going to loop 618 00:44:29,010 --> 00:44:32,850 through every single, uh, task. 619 00:44:32,850 --> 00:44:37,890 Actually we can't name it that, so we'll just name it T for short and total tasks. 620 00:44:37,890 --> 00:44:46,170 What we're going to do is we're going to check if the total is not equal to the fulfilled value. 621 00:44:46,170 --> 00:44:52,200 If it is, then we're just going to return false because clearly we haven't completed all of our tasks 622 00:44:52,200 --> 00:44:52,680 yet. 623 00:44:52,680 --> 00:44:57,240 But if we loop through every single task and all of them have been fulfilled, then we can go ahead 624 00:44:57,240 --> 00:44:58,470 and return true. 625 00:44:59,030 --> 00:44:59,630 Already in. 626 00:44:59,630 --> 00:45:04,490 The next function that I think we can fill out is our disable tasks function. 627 00:45:04,490 --> 00:45:06,440 So this one should be pretty easy to do. 628 00:45:06,440 --> 00:45:12,080 All we're going to do is loop through every single task object inside of our workspace, not Krusty 629 00:45:12,080 --> 00:45:14,030 Krab dot task folder. 630 00:45:14,030 --> 00:45:15,890 We're going to get all the children in there. 631 00:45:16,580 --> 00:45:22,280 And what we're going to do is we're going to get this task object, get the attachment that's inside 632 00:45:22,280 --> 00:45:28,520 of it, and we're going to set the proximity prompt dot enabled equal to false. 633 00:45:28,550 --> 00:45:33,980 Afterwards we can set the Re-fill prompt dot enabled equal to false as well. 634 00:45:33,980 --> 00:45:40,160 And then we're going to use the update UI event and fire to all of the clients in our game to go ahead 635 00:45:40,160 --> 00:45:42,560 and hide their task frame. 636 00:45:42,560 --> 00:45:44,120 So high task frame. 637 00:45:44,120 --> 00:45:50,060 And then we're also going to have to use the game comms event and fire to all of the clients. 638 00:45:50,600 --> 00:45:59,030 To stop playing the task music, because those sound instances have the loop property enabled, so they're 639 00:45:59,030 --> 00:46:03,080 going to be playing forever and ever unless we explicitly tell those clients to stop playing the sound. 640 00:46:03,080 --> 00:46:07,610 So game comms enum client dot two client. 641 00:46:07,610 --> 00:46:10,250 We're going to give them the action to stop the sound. 642 00:46:10,250 --> 00:46:15,770 And the sound we wish to stop playing is going to be the chosen music, and we should be good to go 643 00:46:15,770 --> 00:46:16,280 there. 644 00:46:16,890 --> 00:46:17,700 Okay. 645 00:46:17,700 --> 00:46:23,340 The other functions we can go ahead and fill out is our get completed tasks from function and the Bindable 646 00:46:23,340 --> 00:46:24,660 invoke function. 647 00:46:24,930 --> 00:46:30,480 So when this function gets called, we want to get the total amount of tasks that this player completed. 648 00:46:30,480 --> 00:46:32,550 And this one is going to be really easy. 649 00:46:32,580 --> 00:46:40,920 All we're going to do is we're going to return if inside of the player task totals. 650 00:46:40,920 --> 00:46:42,810 This player has a key in their. 651 00:46:43,930 --> 00:46:49,900 Then we're going to basically just return the table that's inside of player task totals for this particular 652 00:46:49,900 --> 00:46:50,590 player. 653 00:46:51,400 --> 00:46:55,990 Otherwise, if they didn't have a key inside of the player task totals table, then we're just going 654 00:46:55,990 --> 00:47:01,960 to return a table and we can have a key in there that's like completed tasks. 655 00:47:01,960 --> 00:47:03,520 And we'll just set that to zero. 656 00:47:03,760 --> 00:47:08,890 So just in case this player never had a table to begin with, we're just going to give them a table 657 00:47:08,890 --> 00:47:10,600 with zero completed tasks. 658 00:47:10,600 --> 00:47:16,930 Then inside of our on bind invoke function, the action we need to listen to in here is our game comms 659 00:47:16,930 --> 00:47:24,190 enum server dot task service dot get completed tasks for player, and all we're going to do in here 660 00:47:24,190 --> 00:47:29,770 is return true to let them know that this executed successfully, and we're going to return whatever 661 00:47:29,770 --> 00:47:33,010 gets returned from our get completed tasks from. 662 00:47:33,010 --> 00:47:36,940 And then this, uh, action needs to be supplied. 663 00:47:36,940 --> 00:47:39,520 The player we need to get the tasks for. 664 00:47:39,520 --> 00:47:45,070 So inside of the args table, the first key can just be our player object. 665 00:47:45,070 --> 00:47:51,160 So whatever script, uh, executes this function, they'll just pass a table with that player inside 666 00:47:51,160 --> 00:47:53,290 of it and then we return back to them. 667 00:47:53,290 --> 00:47:55,120 That player's completed task. 668 00:47:55,420 --> 00:47:58,270 Otherwise at the end here we're just going to error. 669 00:47:58,510 --> 00:47:59,710 We'll give a message. 670 00:47:59,710 --> 00:48:01,810 We'll say requested action. 671 00:48:01,810 --> 00:48:05,980 We'll put a directive did not match possible actions for. 672 00:48:05,980 --> 00:48:07,330 And then we'll put another directive. 673 00:48:07,330 --> 00:48:11,440 And we'll format this with the two string. 674 00:48:11,440 --> 00:48:13,090 And we'll pass the action here. 675 00:48:13,090 --> 00:48:15,670 And then we'll just pass the script dot name. 676 00:48:15,670 --> 00:48:19,330 So for some reason a developer gives us an action that's incorrect. 677 00:48:19,330 --> 00:48:24,070 Like maybe they accidentally passed set up tasks to our Bindable invoke function. 678 00:48:24,070 --> 00:48:30,580 It'll say requested action, set up tasks did not match possible actions for tasks service. 679 00:48:31,150 --> 00:48:34,450 And that's the error we'll get for our bind double invoke function. 680 00:48:34,840 --> 00:48:35,410 Okay. 681 00:48:35,410 --> 00:48:38,710 And our task service should be all set up. 682 00:48:38,710 --> 00:48:43,870 So now it is time to test whether or not everything is working correctly for our tasks. 683 00:48:47,590 --> 00:48:48,040 All right. 684 00:48:48,040 --> 00:48:50,230 So our music is playing, as you can see. 685 00:48:50,230 --> 00:48:50,740 Perfect. 686 00:48:50,740 --> 00:48:52,540 We have all of our four crates here. 687 00:48:53,770 --> 00:48:57,520 Um, unfortunately, it looks like our main door didn't shut for some reason. 688 00:48:57,520 --> 00:48:58,660 That's kind of interesting. 689 00:48:58,660 --> 00:49:06,130 But anyways, uh, we have each of our crates here, and as you can see, it tells us how much food 690 00:49:06,130 --> 00:49:07,090 is left inside of them. 691 00:49:07,090 --> 00:49:08,860 So if I actually interact with this. 692 00:49:11,020 --> 00:49:11,500 There we go. 693 00:49:11,500 --> 00:49:19,240 We get the food given to us, and if we go ahead and go to the kitchen, we should be able to refill 694 00:49:19,240 --> 00:49:20,110 our fridge. 695 00:49:20,410 --> 00:49:21,250 So there we go. 696 00:49:21,250 --> 00:49:26,470 It took our can, but unfortunately it did not update the tasks for that particular objective. 697 00:49:26,680 --> 00:49:33,820 But it is updating the text inside of these proximity prompts and it's not giving me any extra ones. 698 00:49:33,820 --> 00:49:36,070 And it's telling me you already have food on you. 699 00:49:36,430 --> 00:49:39,130 All right, let's go back. 700 00:49:39,160 --> 00:49:43,240 It did disable the prompt though, because we did fulfill the task, but unfortunately it didn't update 701 00:49:43,240 --> 00:49:44,320 on our screen. 702 00:49:45,520 --> 00:49:52,390 And it does look like we're having our small message text on the bottom of our screen staying stuck 703 00:49:52,390 --> 00:49:53,260 for some reason. 704 00:49:53,260 --> 00:49:55,090 So that's another problem we're going to have to fix. 705 00:49:55,090 --> 00:49:58,000 So let's actually let's go ahead and troubleshoot these real quick. 706 00:49:58,030 --> 00:49:58,540 Alrighty. 707 00:49:58,540 --> 00:50:05,350 So the problem here on the client is that inside of our main UI handler, we actually did not add a 708 00:50:05,350 --> 00:50:09,040 key inside of our case table for when we fulfill a task. 709 00:50:09,040 --> 00:50:10,450 So let's add that real quick. 710 00:50:10,450 --> 00:50:12,160 So GUI actions enum. 711 00:50:13,100 --> 00:50:14,390 Dot task fulfilled. 712 00:50:14,390 --> 00:50:18,470 We need that to refer to our fulfill task function. 713 00:50:19,550 --> 00:50:20,240 All right. 714 00:50:20,240 --> 00:50:21,110 Good to go there. 715 00:50:21,110 --> 00:50:23,900 And then for our display. 716 00:50:23,900 --> 00:50:24,680 Small message. 717 00:50:24,680 --> 00:50:27,080 Unfortunately it does not fade out. 718 00:50:27,080 --> 00:50:30,350 So let's check our logic here real quick. 719 00:50:30,770 --> 00:50:34,430 And I don't see any issues really with our logic here. 720 00:50:34,430 --> 00:50:38,090 So what I could do maybe that error was a fluke for some reason. 721 00:50:38,090 --> 00:50:44,300 But we can print out the small message label dot transparency. 722 00:50:44,660 --> 00:50:51,530 And we can also print out the small message label dot text as well as the text that it's supposed to 723 00:50:51,530 --> 00:50:55,790 match, just to see what these values are exactly for, why this is not fading out. 724 00:50:56,000 --> 00:50:58,580 And we can go ahead and try this out again. 725 00:51:03,300 --> 00:51:03,900 That is strange. 726 00:51:03,900 --> 00:51:08,640 Our door closed this time, so I'm not sure exactly why the door didn't close last time, but if I interact 727 00:51:08,640 --> 00:51:12,810 with it, hopefully we can see why our text isn't fading out. 728 00:51:13,530 --> 00:51:14,910 Okay, this is interesting. 729 00:51:14,910 --> 00:51:20,640 It's printing out one for the transparency of our text, which means our text should be invisible right 730 00:51:20,640 --> 00:51:22,230 now, but it isn't. 731 00:51:22,380 --> 00:51:25,470 So let's check why real quick. 732 00:51:25,470 --> 00:51:27,420 And let's see here. 733 00:51:27,420 --> 00:51:30,390 Oh, it's because I'm a goofball. 734 00:51:30,600 --> 00:51:36,930 Um, we need to check the text transparency of our text and not the transparency. 735 00:51:36,930 --> 00:51:40,920 So we need to change this to text transparency. 736 00:51:40,920 --> 00:51:44,850 And now our text should be able to fade out. 737 00:51:44,850 --> 00:51:46,800 Very simple little mistake. 738 00:51:46,800 --> 00:51:49,170 But something like that can cause a huge headache. 739 00:51:49,170 --> 00:51:55,980 So yeah, make sure we'll change this from transparency to text transparency inside of our main UI handler 740 00:51:55,980 --> 00:51:58,470 and the display small message function. 741 00:51:58,800 --> 00:52:01,080 Okay, let's try this out again. 742 00:52:01,860 --> 00:52:02,700 All right. 743 00:52:02,730 --> 00:52:04,830 Unfortunately, our door did not close again. 744 00:52:04,830 --> 00:52:10,920 And I think the problem with our door is that because we are checking whether or not the door is moving 745 00:52:10,920 --> 00:52:14,760 when we're trying to close it, it doesn't allow us to close the door. 746 00:52:14,760 --> 00:52:19,680 So it appears we might need to remove that if statement when we're trying to close the door from the 747 00:52:19,680 --> 00:52:20,670 server side. 748 00:52:20,670 --> 00:52:21,930 But we'll fix that in a moment. 749 00:52:21,930 --> 00:52:26,160 But we need to check whether when interacting with this prompt, if this is going to disappear. 750 00:52:26,160 --> 00:52:27,600 So this should fade out. 751 00:52:28,200 --> 00:52:30,150 Should fade out any second okay. 752 00:52:30,150 --> 00:52:30,540 There we go. 753 00:52:30,540 --> 00:52:31,020 Perfect. 754 00:52:31,020 --> 00:52:40,230 It fades out if we grab food here and we go to fulfill the task inside of the kitchen, we go do that. 755 00:52:40,230 --> 00:52:41,100 Okay, there we go. 756 00:52:41,100 --> 00:52:44,490 Our task turns green and it updates the count one out of one. 757 00:52:44,490 --> 00:52:47,490 And as you can see, the prompt has disappeared because we've fulfilled that task. 758 00:52:47,850 --> 00:52:50,250 It's also disappeared off of our tasks. 759 00:52:50,430 --> 00:52:56,730 G1 now, if we try to clean the floor, we should get another message. 760 00:52:56,820 --> 00:52:57,330 There we go. 761 00:52:57,330 --> 00:53:00,750 You need a broom for this task and if I try to complete it. 762 00:53:02,590 --> 00:53:05,350 You do not have the required tool needed to complete this task. 763 00:53:05,350 --> 00:53:08,290 Perfect, because we actually need a broom tool. 764 00:53:08,410 --> 00:53:14,290 Now, I've already left these scripts inside of the model or all of the game assets for this game. 765 00:53:14,290 --> 00:53:19,210 It's a very simple script inside of this tool, all it does is just grabs the tool from the workspace 766 00:53:19,210 --> 00:53:21,970 and copies it into the player's inventory when this is clicked. 767 00:53:21,970 --> 00:53:23,230 But now we get our broom. 768 00:53:23,230 --> 00:53:27,220 And if we go over, as you can see, we don't get the message on our screen anymore. 769 00:53:30,090 --> 00:53:33,000 And we unfortunately aren't able to clean up. 770 00:53:33,000 --> 00:53:38,940 Looks like we did get another error in our on prompt triggered function, so we'll fix that in a moment. 771 00:53:38,940 --> 00:53:44,310 But let's go ahead and test out our other, for example our toilet brush. 772 00:53:44,310 --> 00:53:48,840 So let's find where our toilet that needs to be scrubbed is at. 773 00:53:48,840 --> 00:53:49,290 Here we go. 774 00:53:49,290 --> 00:53:50,910 So if we go and clean this toilet. 775 00:53:54,940 --> 00:53:59,530 We get the same error, so we'll fix that in a moment. 776 00:53:59,590 --> 00:54:01,570 Let's go ahead and try out. 777 00:54:01,570 --> 00:54:04,750 This is probably going to give us the same error as well if we try to complete this one. 778 00:54:06,760 --> 00:54:10,840 So we're getting the same error attempt to index nil with text. 779 00:54:10,840 --> 00:54:14,350 So let's go ahead and see what the problem is there okay. 780 00:54:14,350 --> 00:54:19,420 So at line 127 we're getting an error attempt to index nil with text. 781 00:54:19,990 --> 00:54:25,780 So when we index with text here, apparently this is nil. 782 00:54:25,960 --> 00:54:30,970 And that's of course because we didn't pass the name of our task object. 783 00:54:30,970 --> 00:54:32,830 We forgot to pass the name. 784 00:54:34,030 --> 00:54:38,410 And while we're at it, we're also going to go into server script service and we're going to open up 785 00:54:38,410 --> 00:54:39,700 our door service. 786 00:54:40,310 --> 00:54:48,560 And when we want to open and close a door, what we're going to do is we're actually just going to go 787 00:54:48,560 --> 00:54:53,090 ahead and get rid of these if statements of whether or not the door is moving. 788 00:54:53,090 --> 00:54:57,890 So we'll get rid of it out of the close function, and we'll also get rid of it out of the open function. 789 00:54:57,890 --> 00:55:02,930 This means that our front door shouldn't get left open when we touch that part, and the server tries 790 00:55:02,930 --> 00:55:06,290 to close it, okay, fix that as well. 791 00:55:06,560 --> 00:55:07,430 Okay. 792 00:55:07,430 --> 00:55:13,130 So the problem was, is that when I open this door, right, I touch that part inside immediately while 793 00:55:13,130 --> 00:55:14,570 the door was still opening. 794 00:55:14,570 --> 00:55:18,110 So let me open this door and sprint in real fast. 795 00:55:18,110 --> 00:55:22,940 So we'll do that and hopefully the door gets closed. 796 00:55:23,120 --> 00:55:25,760 So we're going to have to wait through this text. 797 00:55:26,210 --> 00:55:26,360 Okay. 798 00:55:26,360 --> 00:55:27,530 If I look behind me. 799 00:55:27,770 --> 00:55:28,430 Perfect. 800 00:55:28,430 --> 00:55:30,860 Our door is indeed closed. 801 00:55:31,370 --> 00:55:34,520 We should be able to fulfill these tasks. 802 00:55:34,520 --> 00:55:35,450 No problem now. 803 00:55:35,450 --> 00:55:39,830 So if I try to clean up this spill on the floor, hopefully we don't get an error. 804 00:55:41,700 --> 00:55:43,560 And unfortunately we did get another error. 805 00:55:43,590 --> 00:55:44,640 This time it's different. 806 00:55:44,640 --> 00:55:46,500 One attempt to index nil will fulfill. 807 00:55:46,500 --> 00:55:50,670 I think we forgot to pass the name of our object again. 808 00:55:50,670 --> 00:55:54,240 So let's hop back into our script I guess. 809 00:55:54,810 --> 00:55:58,890 And of course, we accidentally did the exact same stupid problem here. 810 00:55:58,890 --> 00:56:00,390 And we also did it over here. 811 00:56:00,390 --> 00:56:04,800 So we need to copy this and make sure we're passing the task object name. 812 00:56:05,550 --> 00:56:09,150 Inside of this table instead of the task object itself. 813 00:56:09,150 --> 00:56:11,430 Okay, fix that several more times. 814 00:56:12,240 --> 00:56:13,140 Hopefully. 815 00:56:13,140 --> 00:56:14,610 Hopefully now. 816 00:56:15,170 --> 00:56:17,840 Our problems should be fixed. 817 00:56:17,840 --> 00:56:20,330 So let's go ahead and play test one more time. 818 00:56:21,110 --> 00:56:21,740 Okay. 819 00:56:21,740 --> 00:56:22,760 We get our broom. 820 00:56:23,180 --> 00:56:27,290 If we go clean up this mess here, hopefully we don't get an error. 821 00:56:27,320 --> 00:56:27,770 No error. 822 00:56:27,770 --> 00:56:28,520 Please. 823 00:56:29,030 --> 00:56:30,350 There we go. 824 00:56:30,380 --> 00:56:31,070 All right. 825 00:56:31,070 --> 00:56:32,900 We successfully completed the task. 826 00:56:32,900 --> 00:56:35,210 As you can see, it fulfilled on the top, right. 827 00:56:35,210 --> 00:56:37,820 And that means we should be able to clean our table now. 828 00:56:40,690 --> 00:56:46,000 And unfortunately, when we do it with the crumbs, absolutely nothing happens. 829 00:56:46,510 --> 00:56:47,440 That's another problem. 830 00:56:47,440 --> 00:56:50,230 Looks like we're going to have to figure out why that's not working. 831 00:56:51,150 --> 00:56:54,540 But hopefully, maybe our toilet should be working. 832 00:56:54,540 --> 00:56:57,420 So if we go ahead and find which one, here it is. 833 00:56:57,420 --> 00:56:58,680 We clean this toilet. 834 00:56:59,070 --> 00:57:00,360 Hopefully we don't get an error. 835 00:57:02,980 --> 00:57:03,640 Perfect. 836 00:57:03,640 --> 00:57:06,100 We clean the toilet, the fills on the top right. 837 00:57:06,220 --> 00:57:07,810 All is good there. 838 00:57:08,650 --> 00:57:12,130 If we grab food from here, we get our food. 839 00:57:12,710 --> 00:57:15,470 And then we go and fill that in the kitchen here. 840 00:57:16,040 --> 00:57:16,520 Perfect. 841 00:57:16,520 --> 00:57:18,290 That works just as well. 842 00:57:20,190 --> 00:57:25,110 But unfortunately, it appears that our crumbs. 843 00:57:25,930 --> 00:57:27,370 Are not wanting to be clean. 844 00:57:28,030 --> 00:57:32,980 So back inside of the task service, inside of our on prompt triggered function, we're going to go 845 00:57:32,980 --> 00:57:40,210 back down here where specific tasks such as the dirty water, the crumbs or the broom tasks need to 846 00:57:40,210 --> 00:57:44,590 be fulfilled and we need to figure out why exactly it's working for the other two, but it's not working 847 00:57:44,590 --> 00:57:46,330 for the crumbs task. 848 00:57:46,630 --> 00:57:48,940 So if I look quickly over this. 849 00:57:49,820 --> 00:57:50,570 Oh. 850 00:57:50,660 --> 00:57:57,470 Um, for some reason, we accidentally indented every single thing. 851 00:57:57,940 --> 00:58:02,230 Inside of this if statement that checks whether or not this task needs a required tool. 852 00:58:02,230 --> 00:58:07,360 And since our crumbs don't require a tool, nothing is being executed at all because it doesn't go into 853 00:58:07,360 --> 00:58:08,410 this if statement. 854 00:58:08,410 --> 00:58:11,890 So that's a little bit of an issue. 855 00:58:11,890 --> 00:58:16,990 So what we need to do is we need to copy this and take it and move it out of our if statement and put 856 00:58:16,990 --> 00:58:23,530 this down here, because here is where we specifically check for whether or not the player has the tool 857 00:58:23,530 --> 00:58:25,330 requirements for this task. 858 00:58:25,330 --> 00:58:28,990 And then after that we can go down and fulfill the particular task. 859 00:58:28,990 --> 00:58:35,410 So now our crumb task should be working and our other tasks should be working as well. 860 00:58:35,410 --> 00:58:36,370 Okay. 861 00:58:36,370 --> 00:58:39,430 Now that's an example of a logical error. 862 00:58:39,430 --> 00:58:42,700 Our code not performing the way we expect it to. 863 00:58:43,030 --> 00:58:47,260 Now hopefully everything should be fixed. 864 00:58:48,980 --> 00:58:52,310 Okay, hopefully our crumb task should be working now. 865 00:58:52,310 --> 00:58:54,410 So let's go ahead and find it wherever it's at. 866 00:58:54,410 --> 00:58:55,220 Here it is. 867 00:58:55,760 --> 00:58:56,210 All right. 868 00:58:56,210 --> 00:58:57,530 Please be working. 869 00:58:57,530 --> 00:58:58,460 Please be working. 870 00:58:59,790 --> 00:59:00,390 Perfect. 871 00:59:00,390 --> 00:59:01,440 It works great. 872 00:59:01,620 --> 00:59:03,390 We completed it in the top right. 873 00:59:03,390 --> 00:59:07,440 And then let's go ahead and see if we can complete the other tasks if they're still working. 874 00:59:07,440 --> 00:59:12,450 So if we go and sweep this up here should fulfill as well. 875 00:59:13,260 --> 00:59:13,800 Perfect. 876 00:59:13,800 --> 00:59:14,550 Fulfilled. 877 00:59:14,820 --> 00:59:18,030 If we go and restock the kitchen we should be good. 878 00:59:18,750 --> 00:59:23,670 So we grab our food, we go back into the kitchen. 879 00:59:24,030 --> 00:59:24,750 Okay, perfect. 880 00:59:24,750 --> 00:59:25,710 We refilled it. 881 00:59:26,040 --> 00:59:28,470 And let's go ahead and test out our toilet task. 882 00:59:29,630 --> 00:59:30,470 Find out where it's at. 883 00:59:30,470 --> 00:59:31,130 Here it is. 884 00:59:32,000 --> 00:59:33,140 Clean that up. 885 00:59:35,270 --> 00:59:37,070 And perfect. 886 00:59:37,070 --> 00:59:37,610 All right. 887 00:59:37,610 --> 00:59:41,450 Our task service seems to be working great. 888 00:59:42,840 --> 00:59:47,880 Okay, this lecture got quite long, but you can obviously see the amount of time that it can take to 889 00:59:47,880 --> 00:59:50,070 script and debug our code. 890 00:59:50,100 --> 00:59:52,890 We're going to continue working on our story in the next lecture. 891 00:59:52,890 --> 00:59:55,590 So thanks for sticking around and I'll see you in the next one.